//
//  Volimg_proc.m
//  V3D_Cocoa
//
//  Created by yang liang on 11-3-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Volimg_proc.h"

bool minMaxInVector_char(unsigned char * p, V3DLONG len, V3DLONG *pos_min, unsigned char *minv, V3DLONG *pos_max, unsigned char *maxv)
{
	if (!p || len <= 0)
		return false;
	
	*minv = *maxv = p[0];
	*pos_min = *pos_max = 0;
	for (V3DLONG i=1;i<len;i++)
	{
		if (p[i]>*maxv)
		{
			*maxv = p[i];
			*pos_max = i;
		}
		else if (p[i]<*minv)
		{
			*minv = p[i];
			*pos_min = i;
		}
	}
	
	return true;
}
bool minMaxInVector_int16(USHORTINT16 * p, V3DLONG len, V3DLONG *pos_min, USHORTINT16 *minv, V3DLONG *pos_max, USHORTINT16 *maxv)
{
	if (!p || len <= 0)
		return false;
	
	*minv = *maxv = p[0];
	*pos_min = *pos_max = 0;
	for (V3DLONG i=1;i<len;i++)
	{
		if (p[i]>*maxv)
		{
			*maxv = p[i];
			*pos_max = i;
		}
		else if (p[i]<*minv)
		{
			*minv = p[i];
			*pos_min = i;
		}
	}
	
	return true;
}
bool minMaxInVector_float(float * p, V3DLONG len, V3DLONG *pos_min, float *minv, V3DLONG *pos_max, float *maxv)
{
	if (!p || len <= 0)
		return false;
	
	*minv = *maxv = p[0];
	*pos_min = *pos_max = 0;
	for (V3DLONG i=1;i<len;i++)
	{
		if (p[i]>*maxv)
		{
			*maxv = p[i];
			*pos_max = i;
		}
		else if (p[i]<*minv)
		{
			*minv = p[i];
			*pos_min = i;
		}
	}
	
	return true;
}